#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution01 {
public:
    int triangleNumber(vector<int>& nums) {
        if (nums.size() < 3) return 0;
        long long sum = 0;
        int len = nums.size();
        sort(nums.begin(), nums.end());
        for (int i = len - 1; i >= 2; i--) {
            int pivot = nums[i];
            int right = i - 1, left = 0;
            while (left < right) {
                if (nums[right] + nums[left] > pivot) {
                    sum += right - left;
                    right--;
                }
                else {
                    left++;
                }
            }
        }
        return sum;
    }
};

class Solution02 {
public:
    vector<int> FindTarget(vector<int>& nums, int target) {
        int right = nums.size() - 1, left = 0;
        vector<int> ret;
        while (left < right) {
            int sum = nums[left] + nums[right];
            if (sum == target) {
                ret.push_back(nums[left]);
                ret.push_back(nums[right]);
                break;
            }
            else if (sum > target) {
                right--;
            }
            else {
                left++;
            }
        }
        return ret;
    }
};